import static org.junit.Assert.*;

import javax.persistence.LockModeType;

import name.fowler.refactoring.simplestore.domain.Customer;
import name.fowler.refactoring.simplestore.domain.Movie;
import name.fowler.refactoring.simplestore.domain.Rental;
import name.fowler.refactoring.simplestore.domain.pricecode.PriceCodeChildren;
import name.fowler.refactoring.simplestore.domain.pricecode.PriceCodeNewRelease;
import name.fowler.refactoring.simplestore.domain.pricecode.PriceCodeRegular;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;


public class Transactions extends JPATest {

	Customer customer;
	
	@Before
	public void setUp() {
		super.setUp();
		
		PriceCodeChildren priceCodeChildren = new PriceCodeChildren();
		PriceCodeRegular priceCodeRegular = new PriceCodeRegular();
		PriceCodeNewRelease priceCodeNewRelease = new PriceCodeNewRelease();
		
		customer = new Customer("testCustomer");
		Movie movCinderella = new Movie("Cinderella", priceCodeChildren);
		Rental rental1 = new Rental(1);
		rental1.addMovie(movCinderella);
		customer.addRental(rental1);
		getEm().persist(customer);
		getEm().getTransaction().commit();
	}

	@After
	public void tearDown() {
		super.tearDown();
		getEm().getTransaction().commit();
	}

	@Test
	public void test() {
		getEm().getTransaction().begin();
		customer = getEm().find(Customer.class,  1, LockModeType.PESSIMISTIC_READ);
		customer.setName("111");
		//getEm().merge(customer);
		//fail("Not yet implemented");

	}

}
